package com.baymax.test.scene.span

import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Rect
import android.graphics.RectF
import android.text.style.ReplacementSpan

class Dspan : ReplacementSpan() {
    val padding = 8f
    val span = RectF()
    override fun getSize(
        paint: Paint,
        text: CharSequence?,
        start: Int,
        end: Int,
        fm: Paint.FontMetricsInt?
    ): Int = (paint.measureText(text, start, end) + padding * 2).toInt()

    override fun draw(
        canvas: Canvas,
        text: CharSequence,
        start: Int,
        end: Int,
        x: Float,
        top: Int,
        y: Int,
        bottom: Int,
        paint: Paint
    ) {
        val w = paint.measureText(text, start, end) + padding * 2
        span.set(x, 0f,  x+ w, bottom.toFloat())
        paint.color = 0x7fff0000
        canvas.drawRoundRect(span, padding, padding, paint)
        paint.color = Color.BLACK
        canvas.drawText(text,start ,end , x + padding ,y.toFloat() ,paint)
    }



}
